// 统一管理首页模块接口
import request from "../../utils/request";
import type { LoginRequest, LoginResponse, UpdataUserInfoRequest, GetUserInfoResponse, NoneResponse } from "./type";

enum API {
  LOGOUT_URL = '/user/logout',
  LOGIN_URL = '/user/login',
  REGISTER_URL = '/user/register',
  CAPTCHA_URL = '/user/captcha?',
  GETUSERINFO_URL = '/user',
  UPDATEUSERINFO_URL = '/user/{id}',
  UPDATEUSERROLE_URL = '/user/{id}/{role}',
}

export const reqLogin = (data: any) => request.post<LoginRequest, LoginResponse>(API.LOGIN_URL, data)
export const reqRegister = (data: any) => request.post<LoginRequest, NoneResponse>(API.REGISTER_URL, data)
export const reqCaptcha = () => request.get<any, any>(API.CAPTCHA_URL + new Date().getTime())
export const reqGetUserInfo = (page: number, pageSize: number, username:string, role:string) => request.get<any, GetUserInfoResponse>(API.GETUSERINFO_URL, { params: { page, pageSize, username, role } })
export const reqLogout = () => request.post<any, NoneResponse>(API.LOGOUT_URL)
export const reqUpdateUserInfo = (id: number, data: UpdataUserInfoRequest) => request.put<UpdataUserInfoRequest, NoneResponse>(API.UPDATEUSERINFO_URL.replace('{id}', id.toString()), data)
export const reqDeleteUser = (id: number) => request.delete<any, NoneResponse>(API.UPDATEUSERINFO_URL.replace('{id}', id.toString()))
export const reqDeblockUser = (id: number) => request.patch<any, NoneResponse>(API.UPDATEUSERINFO_URL.replace('{id}', id.toString()))
